﻿using System.Web.Security;
using RLAWEB.Models;
using RLAWEB.RLAServiceReference;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RLAWEB
{
    public partial class ListAchievements : Page
    {
        private RealLifeServiceClient _service;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _service = new RealLifeServiceClient();
                achList.DataSource = GetAchievements();
                achList.DataBind();
            }

            //GridView1.DataSource = GetAchievements();
            //GridView1.DataBind();

            
        }

        private User GetTestUser()
        {
            User user = _service.GetUser("ddd@test.me", "1");
            return user;
        }

        private List<RLAServiceReference.Achievement> GetAchievements()
        {
            List<RLAServiceReference.Achievement> achList = new List<RLAServiceReference.Achievement>();
            var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            if (authCookie != null)
            {
                User loggedInUser = Helper.GetLoggedInUser(authCookie);
                List<UserAchievement> userAchList = _service.GetUserAchievements(loggedInUser);
                achList = userAchList.Select(ua => ua.Achievement).ToList();

            }
            return achList;
        }
    }
}